package com.study.testSpringBoot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.study.testSpringBoot.enumUtil.ServiceBeanEnum;
import com.study.testSpringBoot.factory.ChangeServiceBeanFactory;
import com.study.testSpringBoot.service.IUserService;
import com.study.testSpringBoot.util.SpringUtil;

@RestController
public class ChangeUserController {

	@Autowired
	private IUserService adminUser;
	@Autowired
	private IUserService commonUser;
	
	@GetMapping("/getUser")
	public String getUser(Integer type) {
		// 旧方法，通过ifelse切换service调用
		if(type == 1) {
			adminUser.getUser();
		}
		if(type == 2) {
			commonUser.getUser();
		}
		System.out.println("----------------------------");
		//新方法，通过工厂枚举获取service
		IUserService userService = ChangeServiceBeanFactory.getUserService(type);
		userService.getUser();
		System.out.println("========================");
		return "success";
	}
	
	@GetMapping("/getUser1")
	public String getUser1(Integer type) {
		
		IUserService userService = SpringUtil.getBean(ServiceBeanEnum.getPathByMark(type), IUserService.class);
		userService.getUser();
		System.out.println("===================");
		System.out.println(userService == adminUser);
		return "success";
	}
}
